package cn.jsu.oj.dispatchServer.satellite.netty;

import cn.jsu.oj.dispatchServer.satellite.util.SpringUtil;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

/**
 * netty通道配置
 *
 * @author shan
 * @date 2022/06/29
 */
@Slf4j
@Component("nettyChannel")
@DependsOn("sitePointHandler")
public class NettyChannel extends ChannelInitializer<SocketChannel> {

    /**
     * 注册netty站点处理器
     *
     * @param socketChannel 套接字通道
     */
    @Override
    protected void initChannel(SocketChannel socketChannel) {
        socketChannel.pipeline()
                .addLast(new EntryPointHandler())
                .addLast(SpringUtil.getBean(SitePointHandler.class))
                .addLast(new ExitPointHandler());
    }
}
